<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			
			// 1. 创建字符串
			var str1 = new String("abc123");
			var str2 = "abc";
			
			// 2. 属性
			console.log(str1.length);
			
			// prototype属性
			String.prototype.getLength = function(){
				return this.length;
			}
			var str3 = new String("abcdef");
			console.log(str3.getLength());			
			// constructor属性
			
			// 3. 操作方法
			// 3.1 查找字符串
			// charAt()
			var str4 = "abcdefg";
			console.log(str4.charAt(3));
			for(var i=0;i<str4.length;i++)
			{
				console.log(str4.charAt(i));
			}
			var str5 = "Hello world,world Good Bye world!";
			console.log(str5.indexOf("world"));// 6
			console.log(str5.indexOf("warld"));// -1
			console.log(str5.indexOf("world",11));// 12
			console.log(str5.lastIndexOf("world"));// 27
			
			// 3.2 截取
			// slice(开始的下标,中止的下标)
			// substr(开始的下标,截取的长度)
			// substring(开始的下标,中止的下标)
			
			var str6 = "abcdefghijklmn";
			console.log(str6.slice(3,8)); // 3+5
			console.log(str6.substr(3,5));
			console.log(str6.substring(3,8));
						
			// day05 练习1
			// 写一个函数foo1，传入一个路径字符串
			// 比如d:/abc/aaa/temp1.txt
			// 打印路径信息: d:/abc/aaa/
			// 打印文件名: temp1.txt
			// 打印文件名前缀: temp1
			// 打印文件名后缀： .txt
			
			// 用如下代码测试:
			var filePath = "d:/abc/aaa/temp1.txt";
			foo1(filePath);
			filePath = "c:/1.txt";
			foo1(filePath);
			filePath = "e:/资料/2.html";
			foo1(filePath);
	
			function foo1(path)
			{
				
				//1.查找最后一个/的位置
				var pos = path.lastIndexOf("/");
				//2.截取路径
				var tempPath = path.substr(0,pos+1);
				console.log(tempPath);
				//3.截取文件名
				var fileName = path.substr(pos+1,path.length);
				console.log(fileName);
				//4.文件名查找点的位置
				pos = fileName.indexOf(".");
				//5.截取.的前面
				var name = fileName.substr(0,pos);
				console.log(name);
				//6.截取.及后面
				var ext = fileName.substr(pos,fileName.length);
				console.log(ext);
			}
			
			var str = "aaasdasdada";
			console.log(str.toLowerCase());
			console.log(str.toUpperCase());
			
			var str11 = "abc";
			var str22 = "deef";
			var str33 = "fadga";
			console.log(str1.concat(str22,str33));
			
			var str44 = "aaa,bbb,ccc,d-dd,eee,asdsadsaffas45123";
			var strArr = str44.split(",");
			console.log(strArr);
					
			// 练习2
			// 将以下信息分割放入对象数组
			// 1,张三,18;2,李四,20;3,王五,21
			
			// var stu={}
			// stu.id= 
			// stu.name=
			// stu.age = 
			
			// var stus=[];
			// stus[0] = stu;
			var infoStr = "1,张三,18;2,李四,20;3,王五,21";
			var infoArr = infoStr.split(";");
			for(var i=0;i<infoArr.length;i++)
			{
				var info = infoArr[i];
				console.log(info);
				
				//用，拆分出学生信息
				var stuInfoArr = info.split(",");
				console.log(stuInfoArr);
				
				//创建一个学生对象
				var stu={};
				stu.id = stuInfoArr[0];
				stu.name = stuInfoArr[1];
				stu.age = stuInfoArr[2];
				//放入学生数组
				stu[i] = stu;
				
			}
			console.log(stus);
			
		</script>
		
		
	</body>
</html>